<!DOCTYPE html>

<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">   
    <meta name="viewport"        
        content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>编辑收货地址</title>
    <link rel="stylesheet" href="../public/css/footer.css">
    <link rel="stylesheet" href="../public/css/reset.css">
    <link rel="stylesheet" href="../public/css/all_use.css">
    <link rel="stylesheet" href="../public/css/4.css">
    <script src="../public/js/utils/utils.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<style>
</style>

<body>
    <div id="app">
        <div class="shr">
            <div class="shr1">收货人</div>
            <input placeholder="请输入收货人"
                style="width: 80%;height: 40px;border:none;outline:medium;background-color:#E9E9E9;border-radius: 10px;"
                v-model="username">
        </div>
        <div class="shr">
            <div class="shr1">手机号码</div>
            <input placeholder="请输入手机号码"
                style="width: 80%;height: 40px;border:none;outline:medium;background-color:#E9E9E9;border-radius: 10px;"
                maxlength="11" v-model="tel">
        </div>
        <div class="shr">
            <div class="shr1">收货地址</div>
            <input placeholder="请输入收货地址"
                style="width: 80%;height: 40px;border:none;outline:medium;background-color:#E9E9E9;border-radius: 10px;"
                v-model="site">
        </div>
        <div class="bc" @click="baocun(id)">保存</div>

    </div>
</body>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script type="module">
    import ajax from "../public/js/api/api.js";
    var app = new Vue({
        el: '#app',
        data: {
            index: 0,
            username: '',
            tel: '',
            site: '',
            id: "",
            account: {},
            accountId: '',
        },
        created() {
            this.findAccount2();
            // console.log(this.GetRequest().id, "----this.GetRequest().id----");
            // this.openid = this.GetRequest().openid;
            // this.findAccountById(this.GetRequest().openid);
            // this.findById();
        },
        methods: {
            baocun() {
                if (this.username == "" || this.tel == "" || this.site == "") {
                    alert("请输入完整")
                    return;
                }
                if (this.accountId == "") {
                    ajax
                        .addSite({
                            username: this.username,
                            tel: this.tel,
                            site: this.site,
                        })
                        .then((res) => {
                            if (res.data.code == 0) {
                                // console.log(123);
                                //添加成功返回上一页面
                                // setTimeout(() => {
                                //     history.go(-1);
                                // }, 200);
                                window.onpageshow = function (e) {
                                    if (e.persisted) {
                                        window.location.reload()
                                    }
                                };
                                // window.location.href = `./qrdd.html?id=${this.id}`;         
                            }
                        })
                } else {
                    ajax
                        .updateSite({
                            // accountId: this.accountId,
                            username: this.username,
                            tel: this.tel,
                            site: this.site,
                        })
                        .then((res) => {
                            if (res.data.code == 0) {
                                setTimeout(() => {
                                    history.go(-1);
                                }, 200);
                                // window.location.href = `./qrdd.html?id=${this.id}`; 
                            }
                        })
                }
            },
            findById() {
                ajax
                    .findById({
                        accountId: this.account.id
                    })
                    .then((res) => {
                        if (res.data.code == 0) {
                            // console.log(res.data.data);
                            this.accountId = res.data.data.id;
                            this.username = res.data.data.username;
                            this.tel = res.data.data.tel;
                            this.site = res.data.data.site;
                        }
                    })
            },

            findAccount2: function () {
                ajax
                    .findAccount2()
                    .then((res) => {
                        if (res.data.code == 0) {
                            this.findById(res.data.data.id);
                        }
                    })
            },
        }
    })
</script>

</html>